package com.yht.downloadimage.js.excute;

import java.io.FileReader;

import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

import com.yht.downloadimage.js.method.MethodBase64;

public class JavaExcuteJS {
	public synchronized static String excuteBase64(String entName){
		String str="";
		ScriptEngineManager manager = new ScriptEngineManager();
		ScriptEngine engine = manager.getEngineByName("js");
		FileReader fr=null;
		try {
			fr=new FileReader("D:\\workspace\\yzm\\DowloadFile\\resources\\Base64.js");
			engine.eval(fr);
			if (engine instanceof Invocable) {
				Invocable invocable = (Invocable) engine;
				MethodBase64 executeMethod = invocable.getInterface(MethodBase64.class);
				str=executeMethod.encode(entName);
				//System.out.println(str);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return str;
	}
	public static void main(String[] args) {
		String excuteBase64 = excuteBase64("NUxpdDVadTk1NmU3NVlxbwu002Cu002C");
		System.out.println(excuteBase64);
	}
}
